
package Ajedrez;

class Rey extends Pieza{

    protected int iniX, iniY, finX, finY;

    boolean enrocarLargo = false;
    boolean enrocarCorto = false;

    public Rey() {
    }

    public Rey(int iniX, int iniY, int finX, int finY, boolean enrLargo, boolean enrCorto, boolean blancas) {
        this.iniX = iniX;
        this.iniY = iniY;
        this.finX = finX;
        this.finY = finY;
        int pos[][] = {{1, 0},
            {1, -1},
            {1, 1},
            {-1, -1},
            {-1, 1},
            {-1, -0},
            {0, -1},
            {0, 1},};
        int i, f;
        int r = -1;
        for (int x = 0; x < 8; x++) {
            i = this.iniX + pos[x][0];
            f = this.iniY + pos[x][1];
            if ((i > -1) && (i < 8) && (f > -1) && (f < 8)) {
                if ((i == this.finX) && (f == this.finY)) {
                    corrept = true;
                    r = 1;
                }
            }
        }
        if (r == -1) {
            corrept = false;
        }

        if( blancas ){
            if( enrCorto && finY == 6 ){ // No es necesario comprobar el inicio poque si no es el que debe
                this.corrept = true;     // enrCorto será falso
                this.enrocarCorto = true;
            }
            else if( enrLargo && finY == 2 ){
                this.corrept = true;
                this.enrocarLargo = true;
            }
        }
        else{ //Negras
            if( enrCorto && finY == 6 ){
                this.corrept = true;
                this.enrocarCorto = true;
            }
            else if( enrLargo && finY == 2 ){
                this.corrept = true;
                this.enrocarLargo = true;
            }
        }

    }

    public boolean isEnrocarCorto() {
        return enrocarCorto;
    }

    public boolean isEnrocarLargo() {
        return enrocarLargo;
    }

}
